home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
archives
/
com
/
internet
/
stik
/
gls002b5.zoo
/
gsdaemon.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-13
|
2KB
|
103 lines
#include <osbind.h>
#include <mintbind.h>
#include <string.h>
#include <setjmp.h>
#include <unistd.h>
#include <support.h>
#include "patchlev.h"
#include "global.h"
#include "pipe.h"
long _stksize = 65536L;
extern void dispatch __PROTO((void));
/* in_tfork() -- used in "put-self-in-background" trick. See below. */
static jmp_buf tforkj;
static int in_tfork(arg)
int arg;
{
/* wait for parent to die before we can longjmp back */
while (getppid () > 1)
sleep (1);
longjmp (tforkj, 1);
/*NOTREACHED*/
return 0;
}
/* cleanup() -- free everything we might have alloced, and destroy all
semaphores we might have created. */
static void cleanup(void)
{
cleanup_config();
cleanup_mem();
cleanup_net();
#ifdef DEBUG
cleanup_debug();
#endif
}
int main(void)
{
Cconws("\r\nGlueSTiK\277 STiK emulator for MiNTnet\r\n"
"Network interface daemon\r\n"
"Version " GS_VERSION "\r\n"
"\275 1996-97 Scott Bigham\r\n");
#ifdef DEBUG
Cconws(" Trace logging enabled\r\n");
#endif
#ifdef BLOCK_OPEN
Cconws(" Non-blocking open disabled\r\n");
#endif
#ifdef MULTITHREAD
Cconws(" Multi-threading option available\r\n");
#endif
#ifdef DEBUG
LOG(Pgetpid(), DBG_TRACE, "Starting GSDaemon v%s", GS_VERSION);
#if 0
debug("s", "Starting GSDaemon v" GS_VERSION);
#endif
#endif
if (load_config_file() < 0) {
cleanup();
return -1;
}
#ifdef DEBUG
if (!init_debug()) {
cleanup();
return -1;
}
#endif
if (!init_net()) {
cleanup();
return -1;
}
if (!init_mem()) {
cleanup();
return -1;
}
Cconws("\r\n");
/* "put-self-in-background" trick lifted from syslogd */
#if 0 /* when MiNT gets a non-blocking fork(), this will work */
if (fork())
exit(0);
#else /* until then, we use this */
if (!setjmp(tforkj) && tfork(in_tfork, 0) >= 0)
_exit (0);
#endif
main_loop();
return 0;
}